package com.mvc.form;

import java.lang.reflect.Field;

import javax.servlet.http.HttpServletRequest;

public abstract class ActionForm {
	public ActionForm(){
		
	}
	
	public static ActionForm getFormData(String formBeanName, HttpServletRequest req){
		ActionForm form = null;
		try {
			Class clazz = Class.forName(formBeanName);
			form = (ActionForm) clazz.newInstance();
			Field[] fields = clazz.getDeclaredFields();
			for(Field f:fields){
				f.setAccessible(true);
				f.set(form, req.getParameter(f.getName()));
				f.setAccessible(false);
			}
		} catch (InstantiationException e) {
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			e.printStackTrace();
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		}
		return form;
	}
}
